/****************************************************************************
 *
 * Copyright (C) 2003-2008 Los Alamos National Security, LLC
 *                         Packet Analytics Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 as
 * published by the Free Software Foundation.  You may not use, modify or
 * distribute this program under any other version of the GNU General
 * Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ****************************************************************************/
package nfse.gui.server;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class OpenQuery extends HttpServlet {
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		PrintWriter out = null;
		try {
			response.setContentType("text/html");
			out = response.getWriter();
			String queryID = request.getParameter("queryid");
			LineNumberReader in = new LineNumberReader(new FileReader("/usr/local/netfse/0.3/tomcat5.5/webapps/nfse/NetFSEClient.html"));
			StringBuilder html = new StringBuilder();
			String line = in.readLine();
			while (line != null) {
				html.append(line + "\n");
				if (line.indexOf(" id=\"slot1\"") != -1) {
					html.append("<input type=\"hidden\" name=\"queryid\" id=\"queryid\" value=\"" + queryID + "\">\n");
				}
				line = in.readLine();
			}
			in.close();
			out.println(html.toString());
			out.close();
		} catch (Exception E) {
			E.printStackTrace(out);
		}
	}

}
